//
//  HomeInviteCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/3/24.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "HomeInviteCell.h"

@interface HomeInviteCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *companyLab;
@property (nonatomic, strong) UIImageView *peopleIcon;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UIImageView *phoneIcon;
@property (nonatomic, strong) UILabel *phoneLab;
@property (nonatomic, strong) UIButton *selectBtn;

@end

@implementation HomeInviteCell

+ (instancetype)HomeInviteCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"HomeInviteCell";
    HomeInviteCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[HomeInviteCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, ScreenW - 30, 80)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.companyLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, self.bgView.nim_width - 15 - 60 - 10 - 10, 17)];
        self.companyLab.font = BoldFontOfSize(16);
        self.companyLab.textColor = HexColor(0x2B2C44);
        [self.bgView addSubview:self.companyLab];
        
        self.peopleIcon = [[UIImageView alloc] initWithFrame:CGRectMake(10, self.bgView.nim_height - 10 - 18, 18, 18)];
        [self.peopleIcon setImage:[UIImage imageNamed:@"icon_tran_contacts"]];
        [self.bgView addSubview:self.peopleIcon];
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(self.peopleIcon.nim_right + 3, self.peopleIcon.nim_top + 1.5, (self.bgView.nim_width - 15 - 60 - 10) * 0.5 - (self.peopleIcon.nim_right + 3), 15)];
        self.nameLab.textColor = HexColor(0x585974);
        self.nameLab.font = BoldFontOfSize(14);
        [self.bgView addSubview:self.nameLab];
        
        self.phoneIcon = [[UIImageView alloc] initWithFrame:CGRectMake((self.bgView.nim_width - 15 - 60 - 10) * 0.5, self.peopleIcon.nim_top, 18, 18)];
        [self.phoneIcon setImage:[UIImage imageNamed:@"icon_tran_telephone"]];
        [self.bgView addSubview:self.phoneIcon];
        
        self.phoneLab = [[UILabel alloc] initWithFrame:CGRectMake(self.phoneIcon.nim_right + 3, self.phoneIcon.nim_top + 1.5, (self.bgView.nim_width - 15 - 60 - 10) - (self.phoneIcon.nim_right + 3), 15)];
        self.phoneLab.textColor = HexColor(0x585974);
        self.phoneLab.font = BoldFontOfSize(14);
        [self.bgView addSubview:self.phoneLab];
        
        self.selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.nim_width - 10 - 60, 25, 60, 30)];
        [self.selectBtn setTitle:@"确认" forState:0];
        [self.selectBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.selectBtn.titleLabel.font = BoldFontOfSize(14);
        [self.selectBtn setBackgroundColor:Color_ThemeColor];
        self.selectBtn.layer.masksToBounds = YES;
        self.selectBtn.layer.cornerRadius = 15;
        [self.selectBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.selectBtn];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)btnClick {
    if (self.sureBlock) {
        self.sureBlock();
    }
}

-(void)setModel:(HomeInviteModel *)model {
    _model = model;
    self.companyLab.text = model.name;
    self.phoneLab.text = model.phone;
    self.nameLab.text = model.username;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
